#!C:\pythonCode
# -*- coding: utf-8 -*-
# @Time : 2022/7/7 15:32
# @Author : wangdan
# @File : 回合制游戏-homework.py
# @Software: PyCharm
"""
回合制小游戏，实现创建角色，创建房间，加入房间
无护具收到攻击扣除10血量，有防具扣除5血量
"""
import time

class Role(object):
    role_list = []

    def __init__(self, name, sex):
        self.name = name
        self.sex = sex
        self.HP = 100
        self.equipment = 0
        self.role_list.append(self)
    @staticmethod
    def battle(member1, member2):
        print("开始随机掉落护具.....")
        time.sleep(3)
        factor = int(time.time()%2)
        Role.role_list[factor].equipment = 1
        print(f"恭喜{Role.role_list[factor].name}获得紫金宝甲！！！")
        while member1.HP > 0 and member2.HP >0 :
            member1.HP -= 10/(member1.equipment+1)
            print(f"{member1.name}血量扣除{10/(member1.equipment+1)}，剩余血量为{member1.HP}")
            member2.HP -= 10/(member2.equipment+1)
            print(f"{member2.name}血量扣除{10/(member2.equipment+1)}，剩余血量为{member2.HP}")
            time.sleep(1)
            print("-----------------------")
        print(f"恭喜{sorted(Role.role_list,key=lambda x:x.HP)[-1].name}获胜")
    @classmethod
    def creat_role(cls):
        name = input("请输入你的名字:")
        print("1.男")
        print("2.女")
        sex = input("请选择你的性别:")
        sex_dic = {"1": "男", "2": "女"}
        cls(name, sex_dic[sex])


class Room(object):
    room_dic = {}
    def __init__(self, id):
        self.id = id
        self.num = 1
        self.member = []
        self.room_dic.update({id:self})
    @classmethod
    def join(cls):
        print(f"当前可选房间有：{list(cls.room_dic.keys())}")
        room_number = input("输入要加入的房间号：")
        if len(cls.room_dic[room_number].member) >= 2:
            print("当前房间人数已满")
        else:
            cls.room_dic[room_number].member.append(Role.role_list[-1])

    @classmethod
    def create_room(cls):
        id = input("输入房间号:")
        cls(id)




role_dic = {}
while 1:
    print("1.创建角色\n\
2.创建房间\n\
3.加入房间\n\
4.战斗\n\
5.退出")
    choose = int(input("请输入你的选择:"))
    if choose == 1:
        Role.creat_role()
    elif choose == 2:
        Room.create_room()
    elif choose == 3:
        Room.join()
    elif choose == 4:
        Role.battle(Role.role_list[0],Role.role_list[1])
    else:
        break

